<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/6/24 0024
 * Time: 下午 2:53
 */
/** 上传图片
 * @param \Illuminate\Http\Request $request
 * @return array
 */
function uploadPic(\Illuminate\Http\Request $request)
{
    if($request->isMethod('POST')){
            $file = $request->file('photo');
            // 文件是否上传成功
            if ($file->isValid()) {
                // 原文件名
        //                $yuan = $file->getClientOriginalName();
                // 文件后缀名
                $lastName = $file->getClientOriginalExtension();
                // 文件类型
        //                $type = $file->getClientMimeType();
                // 临时绝对路径
                $path = $file->getRealPath();
                $filename = date('Y-m-d') . '-' . uniqid() . '.' . $lastName;
                $bool = \Illuminate\Support\Facades\Storage::disk('pic')->put($filename, file_get_contents($path));
                if ($bool){
                    return array('code' => 200, 'url' => '/uploads/pic/'. $filename);
                }else{
                    return array('code' => 205, 'url' => '');
                }
            }else{
                //文件不合法
                return array('code' => '205', 'url' => '');
            }
        }
}